774D - Lie or Truth - CodeForces Solution


*special problem constructive algorithms implementation sortings *1500

Please click on ads to support us..

Python Code:

n, l, r = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
a1=a2=a3=b1=b2=b3=None
if l==1:
    a2=a[0:r]
    a3=a[r::]
    b2=b[0:r]
    b3=b[r::]
elif l==2:
    a1=a[0]
    a2=a[1:r]
    a3=a[r::]
    b1=b[0]
    b2=b[1:r]
    b3=b[r::]
else:
    a1=a[0:l-1]
    a2=a[l-1:r]
    a3=a[r::]
    b1=b[0:l-1]
    b2=b[l-1:r]
    b3=b[r::]
a2.sort()
b2.sort()
print("TRUTH" if a1==b1 and a2==b2 and a3==b3 else "LIE")

C++ Code:

#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long int   

/*
TARGET : 3 questions in Div 2, in (1/2) hr.
*/

int main(){
	ll n;
	cin>>n;
	ll a,b;
	cin>>a>>b;
	a--;
	b--;
	vector<ll>v(n);
	for(ll i =0;i<n;i++){
		cin>>v[i];
	}
	vector<ll>vk(n);
	for(ll i =0;i<n;i++){
		cin>>vk[i];
	}
	bool ok = true;
	for(ll i = 0;i<a;i++){
		if(v[i]!=vk[i]){
			ok = false;
		}
	}
	for(ll j = b+1;j<n;j++){
		if(v[j]!=vk[j]){
			ok = false;
		}
	}
	if(ok==false){
		cout<<"LIE"<<endl;
	}
	else{
		map<ll,ll>mp;
		map<ll,ll>mp1;
		for(ll i  =a;i<=b;i++){
			mp[v[i]]++;
			mp1[vk[i]]++;
		}
		for(auto i:mp){
			if(i.second!=mp1[i.first]){
				ok = false;
			}
		}
		for(auto i:mp1){
			if(i.second!=mp[i.first]){
				ok = false;
			}
		}
		if(ok){
			cout<<"TRUTH"<<endl;
		}
		else{
			cout<<"LIE"<<endl;
		}
	}
}


Comments

Submit
0 Comments
More Questions

630P - Area of a Star
1030C - Vasya and Golden Ticket
1529D - Kavi on Pairing Duty
1743A - Password
1743B - Permutation Value
1743C - Save the Magazines
1743D - Problem with Random Tests
1070K - Video Posts
767C - Garland
1201B - Zero Array
1584C - Two Arrays
1131C - Birthday
1285B - Just Eat It
1743F - Intersection and Union
771A - Bear and Friendship Condition
1208E - Let Them Slide
656A - Da Vinci Powers
1025A - Doggo Recoloring
257A - Sockets
231C - To Add or Not to Add
1454E - Number of Simple Paths
931B - World Cup
934B - A Prosperous Lot
999B - Reversing Encryption
1238D - AB-string
810B - Summer sell-off
84A - Toy Army
185A - Plant
1749A - Cowardly Rooks
1749C - Number Game